package enemies;

import java.awt.Dimension;
import java.awt.geom.Point2D;
import java.util.ArrayList;

import javax.swing.ImageIcon;

public abstract class MobileEnemy extends Enemy{

	protected ImageIcon deviceImage;
	protected int deviceAngle = 0;
	
	MobileEnemy(ArrayList<Point2D.Double> route, Point2D.Double position, int health, Dimension size, ImageIcon image, int firerate, int range, int speed, ImageIcon deviceImage, int deviceAngle){
		super( route, position, health, size, image, firerate, range, speed );
		this.deviceAngle = deviceAngle;
		this.deviceImage = deviceImage;
	}
	
	public int getDeviceAngle(){
		return deviceAngle;
	}
	public void setDeviceAngle(int d){
		deviceAngle = d;
	}
	public boolean update(){

		super.update();
		if(aimAtTower != null){
		double x = aimAtTower.getPosition().x-position.x;
		double y = aimAtTower.getPosition().y-position.y;
		//tower links van enemy
		if( x < 0 ){
			//tower hoger dan enemy
			x *= -1;
			if( y < 0 ){
				y *= -1;
				deviceAngle = (int)Math.toDegrees( (Math.atan( ( y/x )   )) ) + 90 ;
			}
			//tower lager dan enemy
			else if( y >= 0 ){
				deviceAngle = (int)Math.toDegrees( (Math.atan( ( x/y )   )) );
			}
			//tower rechts van enemy
		} else if( x >= 0 ){
			if( y < 0 ){
				y *= -1;
				deviceAngle = (int)Math.toDegrees( (Math.atan( ( x/y )   )  ) )+ 180;
			} else if( y >= 0 ){
				deviceAngle = (int)Math.toDegrees( (Math.atan( ( y/x  )   ))   )+ 270;
			}
		}
		}else{
			deviceAngle = this.viewAngle;
		}
		return true;
	}
}
